package com.g3.zoosite.service.impl;

import com.g3.zoosite.model.DwAnimalNews;
import com.g3.zoosite.mapper.DwAnimalNewsMapper;
import com.g3.zoosite.service.IDwAnimalNewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 动物趣闻表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2021-09-28
 */
@Service
public class DwAnimalNewsServiceImpl extends ServiceImpl<DwAnimalNewsMapper, DwAnimalNews> implements IDwAnimalNewsService {
    @Autowired(required = false)
    DwAnimalNewsMapper dwAnimalNewsMapper;

    //图片服务器地址
    @Value("${image-server}")
    private String imageServer;

    /**
     * 查询所有动物趣闻业务逻辑层方法
     */
    @Override
    public List<DwAnimalNews> findAnimalNews() {
        List<DwAnimalNews> animalNews = dwAnimalNewsMapper.selectList(null);
        for(int i=0;i<animalNews.size();i++){
            DwAnimalNews dwAnimalNews = animalNews.get(i);
            //拼接图片服务器和图片路径
            dwAnimalNews.setImagePath(imageServer + dwAnimalNews.getImagePath());
        }
        return animalNews;
    }

    /**
     * 按ID查询动物趣闻业务逻辑层方法
     */
    @Override
    public DwAnimalNews findAnimalNewsById(Integer id) {
        DwAnimalNews animalNew = dwAnimalNewsMapper.selectById(id);
        //拼接图片服务器和图片路径
        animalNew.setImagePath(imageServer+animalNew.getImagePath());
        return animalNew;
    }
}
